import java.util.Arrays;
import java.util.HashSet;
import java.util.TreeSet;

/**
 * @author wangj881
 * @date 2024-12-24 10:56
 */
public class L128_3 {

    public static void main(String[] args) {
        int[] nums = {4,0,-4,-2,2,5,2,0,-8,-8,-8,-8,-1,7,4,5,5,-4,6,6,-3};
        int i = new Solution().longestConsecutive(nums);
        System.out.println(i);
    }


    static class Solution {
        public int longestConsecutive(int[] nums) {
            if (nums.length == 0) {
                return 0;
            }
            TreeSet<Integer> set = new TreeSet<>();
            for (int num : nums) {
                set.add(num);
            }
            int tmp = Integer.MIN_VALUE;
            int res = 1;
            int result = 1;
            for (Integer integer : set) {
                if (tmp == Integer.MIN_VALUE) {
                    tmp = integer + 1;
                    continue;
                }
                if (tmp == integer) {
                    tmp++;
                    res++;
                } else {
                    tmp = integer + 1;
                    res = 1;
                }
                result = Math.max(res, result);
            }
            return result;
        }
    }
}
